#include "src/debugger.cpp"
#include "src/reader.cpp"

extern byte codes[0x10000];
extern byte data[0x10000];
extern byte stack[0x10000];
extern byte buffer[0x10000];

extern qword iregs[128];
extern real4 fregs[64];
extern real8 dregs[64];

static void init()
{
    iregs[Flag] |= (RUNNING + ZERO + STACK_EMPTY);
}

#ifdef __debug__
int main()
{
    init();
    std::string filename;
    std::cout << "Input filename:";
    std::cin >> filename;
    getpHeader(filename.c_str(), getHeader(filename.c_str()));
    loadImage(filename.c_str());
    while (1)
        debug();
    return 0;
}
#else
int main(int argc, char **argv)
{
    init();
    if (argc < 2)
    {
        std::cout << "fatal error:no file used.\n";
        exit(1);
    }
    else
    {
        getpHeader(argv[1], getHeader(argv[1]));
        loadImage(argv[1]);
        while ((iregs[Flag] & RUNNING) && !(iregs[Flag] & (ERROR + DEBUG)))
            debug(argc - 2, argv + 2);
    }
}
#endif